<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class AdminVendors extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	public function index()
	{
		$this->load->view('v_adminvendors');
	}
	
	public function getvendors()
	{
		$this->load->model('m_adminvendors');
		
		$json = $this->m_adminvendors->get_vendors();
		
		$jsonObject = json_decode($json);
		
		$aaData = array();
		
		foreach($jsonObject->aaData as $row)
		{
			if($row['4'] == 1)
			{
				$row['4'] = '<input name="enabled" value="enabled" type="checkbox" onclick="closedclicked(this.checked, ' . $row[0] . ')" checked>';
			}
			else
			{
				$row['4'] = '<input name="enabled" value="enabled" type="checkbox" onclick="closedclicked(this.checked, ' . $row[0] . ')">';
			}
			
			$row['DT_RowId'] = $row[0];
			
			array_push($aaData, $row); 
		}
		
		$jsonObject->aaData = $aaData;
		
		echo json_encode($jsonObject);
	}
	
	public function edit()
	{
		$prevalue = $this->input->post("prevalue", TRUE);
		$value = $this->input->post("value", TRUE);
		$column_index = $this->input->post("column_index", TRUE);
		$row_id = $this->input->post("row_id", TRUE);
		
		$this->load->model('m_adminvendors');
		
		switch($column_index)
		{
			case 0: $this->m_adminvendors->set_vendorid($value, $row_id); break;
			case 1: $this->m_adminvendors->set_vendorname($value, $row_id); break;
			case 2: $this->m_adminvendors->set_email($value, $row_id); break;
			case 3: $this->m_adminvendors->set_sources($value, $row_id); break;
		}

		echo $value;
	}
	
	public function closedchanged()
	{
		$userId = $_POST['userId'];
		$checked = $_POST['checked'];
		
		$this->load->model('m_adminvendors');
		
		if($checked == "true")
		{
			$this->m_adminvendors->updateclosed(1, $userId);
		}
		else
		{
			$this->m_adminvendors->updateclosed(0, $userId);
		}
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */